$OpenBSD: patch-plugins_decoder_musepack_k3bmpcwrapper_cpp,v 1.1 2012/05/24 18:36:45 shadchin Exp $
--- plugins/decoder/musepack/k3bmpcwrapper.cpp.orig	Fri Nov  2 14:55:03 2007
+++ plugins/decoder/musepack/k3bmpcwrapper.cpp	Mon Jan  2 21:54:47 2012
@@ -19,32 +19,32 @@
 #include <qfile.h>
 
 
-mpc_int32_t read_impl( void* data, void* ptr, mpc_int32_t size )
+mpc_int32_t read_impl( mpc_reader *p_reader, void* ptr, mpc_int32_t size )
 {
-  QFile* input = static_cast<QFile*>( data );
+  QFile* input = static_cast<QFile*>( p_reader->data );
   return input->readBlock( (char*)ptr, size );
 }
 
 
-mpc_bool_t seek_impl( void* data, mpc_int32_t offset )
+mpc_bool_t seek_impl( mpc_reader *p_reader, mpc_int32_t offset )
 {
-  QFile* input = static_cast<QFile*>( data );
+  QFile* input = static_cast<QFile*>( p_reader->data );
   return input->at( offset );
 }
 
-mpc_int32_t tell_impl( void* data )
+mpc_int32_t tell_impl( mpc_reader *p_reader )
 {
-  QFile* input = static_cast<QFile*>( data );
+  QFile* input = static_cast<QFile*>( p_reader->data );
   return input->at();
 }
 
-mpc_int32_t get_size_impl( void* data )
+mpc_int32_t get_size_impl( mpc_reader *p_reader )
 {
-  QFile* input = static_cast<QFile*>( data );
+  QFile* input = static_cast<QFile*>( p_reader->data );
   return input->size();
 }
 
-mpc_bool_t canseek_impl( void* )
+mpc_bool_t canseek_impl( mpc_reader * )
 {
   return true;
 }
@@ -74,8 +74,6 @@ K3bMpcWrapper::K3bMpcWrapper()
   m_reader->canseek  = canseek_impl;
   m_reader->data     = m_input;
 
-  m_decoder          = new mpc_decoder;
-
   m_info             = new mpc_streaminfo;
 }
 
@@ -85,7 +83,8 @@ K3bMpcWrapper::~K3bMpcWrapper()
   close();
 
   delete m_reader;
-  delete m_decoder;
+  if (m_demux)
+    mpc_demux_exit(m_demux);
   delete m_info;
   delete m_input;
 }
@@ -98,24 +97,15 @@ bool K3bMpcWrapper::open( const QString& filename )
   m_input->setName( filename );
 
   if( m_input->open( IO_ReadOnly ) ) {
-    mpc_streaminfo_init( m_info );
-    if( mpc_streaminfo_read( m_info, m_reader ) != ERROR_CODE_OK ) {
-      kdDebug() << "(K3bMpcWrapper) Not a valid musepack file: \"" << filename << "\"" << endl;
+    m_demux = mpc_demux_init(m_reader);
+    if (!m_demux)
       return false;
-    }
-    else {
-      mpc_decoder_setup( m_decoder, m_reader );
-      if( !mpc_decoder_initialize( m_decoder, m_info ) ) {
-	kdDebug() << "(K3bMpcWrapper) failed to initialize the Musepack decoder." << endl;
-	close();
-	return false;
-      }
-      else {
-	kdDebug() << "(K3bMpcWrapper) valid musepack file. " 
-		  << channels() << " Channels and Samplerate: " << samplerate() << endl;
-	return true;
-      }
-    }
+
+    mpc_demux_get_info(m_demux, m_info);
+
+    kdDebug() << "(K3bMpcWrapper) valid musepack file. "
+      << channels() << " Channels and Samplerate: " << samplerate() << endl;
+    return true;
   }
   else
     return false;
@@ -130,11 +120,21 @@ void K3bMpcWrapper::close()
 
 int K3bMpcWrapper::decode( char* data, int max )
 {
+  mpc_frame_info frame;
+  mpc_status status;
+
   // FIXME: make this a member variable
   MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH];
 
-  unsigned int samples = mpc_decoder_decode( m_decoder, sample_buffer, 0, 0 );
+  frame.buffer = sample_buffer;
+  status = mpc_demux_decode(m_demux, &frame);
+  if (status != MPC_STATUS_OK) {
+    kdDebug() << "(K3bMpcWrapper) failed to decode sample." << endl;
+    return -1;
+  }
 
+  unsigned int samples = frame.samples;
+
   if( samples*channels()*2 > (unsigned int)max ) {
     kdDebug() << "(K3bMpcWrapper) buffer not big enough." << endl;
     return -1;
@@ -170,7 +170,7 @@ int K3bMpcWrapper::decode( char* data, int max )
 
 bool K3bMpcWrapper::seek( const K3b::Msf& msf )
 {
-  return mpc_decoder_seek_seconds( m_decoder, (double)msf.totalFrames()/75.0 );
+  return mpc_demux_seek_second(m_demux, (double)msf.totalFrames()/75.0) == MPC_STATUS_OK;
 }
 
 
